import configdata from './config'
import api from './httpLbApi.js'
var version_no = '1.0'
let market = ''
let device = uni.getSystemInfoSync().platform;
if (/ios/i.test(device)) {
    market = 'ios'
} else if (/android/i.test(device)) {
    market = 'android'
}
let header = {
    "Authorization": uni.getStorageSync('token'),
    'market': market,
    'version_no': version_no
}
module.exports = {
    // post请求
    post (url, data) {
        url = configdata.APIHOST + url;//请求地址+接口
        return new Promise((resolve, reject) => {
            uni.request({
                url: url,
                data: {
                    ...data,
                    token: uni.getStorageSync('token')
                },
                method: 'POST',
                header: header,
                success: (res) => {
                    if (res.data.code == 200 || res.data.code == 300) {
                        resolve(res.data);
                    } else {
                        uni.showToast({
                            title: res.data.msg,
                            icon: 'none'
                        });
                        resolve();
                    }
                },
                fail: (err) => {
                    reject(err);
                }
            })
        })
    },
    get (url, data) {
        url = configdata.APIHOST + url;
        return new Promise((resolve, reject) => {
            uni.request({
                url: url,
                data: {
                    ...data,
                    token: uni.getStorageSync('token')
                },
                method: 'GET',
                header: header,
                success: (res) => {
                    if (res.data.code == 200 || res.data.code == 300) {
                        resolve(res.data);
                    } else {
                        uni.showToast({
                            title: res.data.msg,
                            icon: 'none'
                        });
                        resolve();
                    }
                },
				
                fail: (err) => {
                    reject(err);
                }
            })
        })
    }
}
